﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Windows.Forms;
using HML.Design;

namespace HML
{
    /// <summary>
    /// 多点滑块控件
    /// </summary>
    [Description("多点滑块控件")]
    [DefaultProperty("Items")]
    [DefaultEvent("ValueChanged")]
    [TypeConverter(typeof(MultidropSlideConverter))]
    [Designer(typeof(MultidropSlideDesigner))]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(MultidropSlide), "Controls.MultidropSlide.Resources.MultidropSlide.bmp")]
    public class MultidropSlide : DpiControl, ISkinObject
    {
        #region 主题

        private SkinObjectXmlMetadata skinObjectXmlMetadata = null;
        /// <summary>
        /// 主题对象在主题文件信息
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SkinObjectXmlMetadata SkinObjectXmlMetadata
        {
            get
            {
                if (this.skinObjectXmlMetadata == null)
                    this.skinObjectXmlMetadata = new SkinObjectXmlMetadata(Assembly.GetAssembly(typeof(MultidropSlide)).GetName().Name, typeof(MultidropSlide).Name);

                return this.skinObjectXmlMetadata;
            }
        }

        private SkinController skinController = null;
        /// <summary>
        /// 主题控制器
        /// </summary>
        [Description("主题控制器")]
        [Category("杂项")]
        [PropertyOrder(-360)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinController SkinController
        {
            get { return this.skinController; }
            set
            {
                if (this.skinController == value)
                    return;

                if (this.skinController != null)
                    this.skinController.RemoveSkinObject(this);

                this.skinController = value;

                if (this.skinController != null)
                    this.skinController.AddSkinObject(this);
            }
        }

        private SkinEnabledState skinEnabled= SkinEnabledState.Auto;
        /// <summary>
        /// 主题是否启用
        /// </summary>
        [Description("主题是否启用")]
        [Category("杂项")]
        [PropertyOrder(-300)]
        [DefaultValue(SkinEnabledState.Auto)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinEnabledState SkinEnabled
        {
            get { return this.skinEnabled; }
            set
            {
                if (this.skinEnabled == value)
                    return;

                this.skinEnabled = value;
                this.OnSkinChanged();
            }
        }

        private SkinStyle skinStyle = SkinStyle.Normal;
        /// <summary>
        /// 主题风格
        /// </summary>
        [Description("主题风格")]
        [Category("杂项")]
        [PropertyOrder(-260)]
        [DefaultValue(SkinStyle.Normal)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinStyle SkinStyle
        {
            get { return this.skinStyle; }
            set
            {
                if (this.skinStyle == value)
                    return;

                this.skinStyle = value;
                this.OnSkinChanged();
            }
        }

        private StyleAppearanceObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [PropertyOrder(-199)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleAppearanceObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleAppearanceObject(this, null);
                return this.stateAppearance;
            }
        }

        /// <summary>
        /// 主题已更改
        /// </summary>
        public virtual void OnSkinChanged()
        {
            SkinManager.SyncSkinValueToProperty(this);
            this.Invalidate();
        }

        private ISkinObject followSkinObject = null;
        /// <summary>
        /// 主题设置跟随指定主题对象（自己的设置不再生效，提供给代码使用）
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual ISkinObject FollowSkinObject
        {
            get { return this.followSkinObject; }
            set
            {
                if (this.followSkinObject == value)
                    return;

                this.followSkinObject = value;
                this.OnSkinChanged();
            }
        }

        public virtual bool GetSkinObjectSkinStateCore()
        {
            return SkinManager.GetSkinObjectSkinState(this.FollowSkinObject ?? this);
        }

        void ISkinObject.InitializeInvalidate()
        {
            this.InitializeElement();
            this.Invalidate();
        }

        void ISkinObject.Invalidate()
        {
            this.Invalidate();
        }

        #endregion

        #region 新增事件

        public delegate void ValueChangedEventHandler(object sender, MultidropSlideValueChangedEventArgs e);
        private static readonly object EventValueChanged = new object();
        /// <summary>
        /// 滑块值更改事件
        /// </summary>
        [Description("滑块值更改事件")]
        public event ValueChangedEventHandler ValueChanged
        {
            add { Events.AddHandler(EventValueChanged, value); }
            remove { Events.RemoveHandler(EventValueChanged, value); }
        }

        public delegate void ValueFormatEventHandler(object sender, MultidropSlideValueFormatEventArgs e);
        private static readonly object EventValueFormat = new object();
        /// <summary>
        /// 滑块值格式化事件
        /// </summary>
        [Description("滑块值格式化事件")]
        public event ValueFormatEventHandler ValueFormat
        {
            add { Events.AddHandler(EventValueFormat, value); }
            remove { Events.RemoveHandler(EventValueFormat, value); }
        }

        #endregion

        #region 停用事件

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler PaddingChanged
        {
            add { base.PaddingChanged += value; }
            remove { base.PaddingChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TextChanged
        {
            add { base.TextChanged += value; }
            remove { base.TextChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler FontChanged
        {
            add { base.FontChanged += value; }
            remove { base.FontChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler RightToLeftChanged
        {
            add { base.RightToLeftChanged += value; }
            remove { base.RightToLeftChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ImeModeChanged
        {
            add { base.ImeModeChanged += value; }
            remove { base.ImeModeChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageChanged
        {
            add { base.BackgroundImageChanged += value; }
            remove { base.BackgroundImageChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageLayoutChanged
        {
            add { base.BackgroundImageLayoutChanged += value; }
            remove { base.BackgroundImageLayoutChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackColorChanged
        {
            add { base.BackColorChanged += value; }
            remove { base.BackColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ForeColorChanged
        {
            add { base.ForeColorChanged += value; }
            remove { base.ForeColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler Click
        {
            add { base.Click += value; }
            remove { base.Click -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler DoubleClick
        {
            add { base.DoubleClick += value; }
            remove { base.DoubleClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseClick
        {
            add { base.MouseClick += value; }
            remove { base.MouseClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseDoubleClick
        {
            add { base.MouseDoubleClick += value; }
            remove { base.MouseDoubleClick -= value; }
        }

        #endregion

        #region 新增属性

        private MultidropSlideOrientation orientation = MultidropSlideOrientation.HorizontalTop;
        /// <summary>
        /// 显示方位
        /// </summary>
        [Description("显示方位")]
        [Category("杂项")]
        [PropertyOrder(-198)]
        [DefaultValue(MultidropSlideOrientation.HorizontalTop)]
        public MultidropSlideOrientation Orientation
        {
            get { return this.orientation; }
            set
            {
                if (this.orientation == value)
                    return;

                this.orientation = value;
                this.InitializeElement();
                this.Invalidate();
            }
        }

        private MultidropSlideTrackMargin orientationMargin = new MultidropSlideTrackMargin(6, 6, 6);
        /// <summary>
        /// 轨道停靠外边距
        /// </summary>
        [Description("轨道停靠外边距")]
        [PropertyOrder(-194)]
        [DefaultValue(typeof(MultidropSlideTrackMargin), "6,6,6")]
        public MultidropSlideTrackMargin OrientationMargin
        {
            get { return this.orientationMargin; }
            set
            {
                if (this.orientationMargin == value)
                    return;

                this.orientationMargin = value;
                this.InitializeElement();
                this.Invalidate();
            }
        }

        private TrackObject track;
        /// <summary>
        /// 轨道
        /// </summary>
        [Description("轨道")]
        [Category("杂项")]
        [PropertyOrder(-175)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public TrackObject Track
        {
            get
            {
                if (this.track == null)
                    this.track = new TrackObject(this);
                return this.track;
            }
        }

        private ThumbObject thumb;
        /// <summary>
        /// 拇指
        /// </summary>
        [Description("拇指")]
        [Category("杂项")]
        [PropertyOrder(-173)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ThumbObject Thumb
        {
            get
            {
                if (this.thumb == null)
                    this.thumb = new ThumbObject(this);
                return this.thumb;
            }
        }

        private TipTitleObject tipTitle;
        /// <summary>
        /// 标题提示
        /// </summary>
        [Description("标题提示")]
        [Category("杂项")]
        [PropertyOrder(-170)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public TipTitleObject TipTitle
        {
            get
            {
                if (this.tipTitle == null)
                    this.tipTitle = new TipTitleObject(this);
                return this.tipTitle;
            }
        }

        private TipValueObject tipValue;
        /// <summary>
        /// 值提示
        /// </summary>
        [Description("值提示")]
        [Category("杂项")]
        [PropertyOrder(-168)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public TipValueObject TipValue
        {
            get
            {
                if (this.tipValue == null)
                    this.tipValue = new TipValueObject(this);
                return this.tipValue;
            }
        }

        private MultidropSlideThumbCollection multidropSlideLumpCollection;
        /// <summary>
        /// 滑块集合
        /// </summary>
        [Description("滑块集合")]
        [Category("杂项")]
        [PropertyOrder(-166)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public MultidropSlideThumbCollection Items
        {
            get
            {
                if (this.multidropSlideLumpCollection == null)
                    this.multidropSlideLumpCollection = new MultidropSlideThumbCollection(this);
                return this.multidropSlideLumpCollection;
            }
        }

        private double maxValue = 100;
        /// <summary>
        /// 最大值
        /// </summary>
        [Description("最大值")]
        [Category("杂项")]
        [PropertyOrder(-164)]
        [DefaultValue(100D)]
        public double MaxValue
        {
            get { return this.maxValue; }
            set
            {
                if (this.maxValue == value)
                    return;

                this.maxValue = value;
                if (this.minValue > value)
                {
                    this.minValue = value;
                }
                for (int i = 0; i < this.Items.Count; i++)
                {
                    if (this.Items[i].SelfValue > value)
                    {
                        this.Items[i].ChangeSelfValue(value, true);
                    }
                }

                this.InitializeElement();
                this.Invalidate();
            }
        }

        private double minValue = 0;
        /// <summary>
        /// 最小值
        /// </summary>
        [Description("最小值")]
        [Category("杂项")]
        [PropertyOrder(-162)]
        [DefaultValue(0D)]
        public double MinValue
        {
            get { return this.minValue; }
            set
            {
                if (this.minValue == value)
                    return;

                this.minValue = value;
                if (this.maxValue < value)
                {
                    this.maxValue = value;
                }
                for (int i = this.Items.Count - 1; i >= 0; i--)
                {
                    if (this.Items[i].SelfValue < value)
                    {
                        this.Items[i].ChangeSelfValue(value, true);
                    }
                }

                this.InitializeElement();
                this.Invalidate();
            }
        }

        private double smallChange = 1;
        /// <summary>
        /// 键盘Up、Down 或 鼠标滚轮上下键移动 最小间隔值
        /// </summary>
        [Description("键盘Up、Down 或 鼠标滚轮上下键移动 最小间隔值")]
        [Category("杂项")]
        [PropertyOrder(-160)]
        [DefaultValue(1D)]
        public double SmallChange
        {
            get { return this.smallChange; }
            set
            {
                if (this.smallChange == value || value <= 0)
                    return;

                this.smallChange = value;
            }
        }

        #endregion

        #region 重写属性

        protected override Size DefaultSize
        {
            get { return new Size(200, 50); }
        }

        protected override ImeMode DefaultImeMode
        {
            get { return ImeMode.Disable; }
        }

        #endregion

        #region 停用属性

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Padding Padding
        {
            get { return base.Padding; }
            set { base.Padding = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string Text
        {
            get { return base.Text; }
            set { base.Text = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Font Font
        {
            get { return base.Font; }
            set { base.Font = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft
        {
            get { return base.RightToLeft; }
            set { base.RightToLeft = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImeMode ImeMode
        {
            get { return base.ImeMode; }
            set { base.ImeMode = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Image BackgroundImage
        {
            get { return base.BackgroundImage; }
            set { base.BackgroundImage = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override ImageLayout BackgroundImageLayout
        {
            get { return base.BackgroundImageLayout; }
            set { base.BackgroundImageLayout = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color BackColor
        {
            get { return this.StyleAppearance.BackColor; }
            set { }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color ForeColor
        {
            get { return this.StyleAppearance.Normal.ThumbBackColor; }
            set { }
        }

        #endregion

        #region 字段

        /// <summary>
        /// 控件激活显示状态（配合Focused 、ShowFocusCues、activatedIndex使用）
        /// </summary>
        private bool activatedState = false;
        /// <summary>
        /// 控件激活状态选项索引
        /// </summary>
        private int activatedIndex = -1;

        /// <summary>
        /// 当前鼠标已按下的对象索引
        /// </summary>
        private int mousedownobjectindex = -1;
        /// <summary>
        /// 当前鼠标已按下的对象的value
        /// </summary>
        private decimal mousedownobjectvalue = -1;
        /// <summary>
        /// 当前鼠标已按下的坐标
        /// </summary>
        private Point mousedownpoint = Point.Empty;

        /// <summary>
        /// 内容内边距
        /// </summary>
        private int contentPadding = 2;

        /// <summary>
        /// 轨道的开始坐标（以滑块矩形中心点为参考点）
        /// </summary>
        protected PointF pole_start_point = PointF.Empty;
        /// <summary>
        /// 轨道的结束坐标（以滑块矩形中心点为参考点）
        /// </summary>
        protected PointF pole_end_point = PointF.Empty;

        /// <summary>
        /// 标题提示间距
        /// </summary>
        private int tipTitleInterval = 3;
        /// <summary>
        /// 值提示间距
        /// </summary>
        private int tipValueInterval = 3;

        #endregion

        public MultidropSlide()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.StandardClick, false);//自定义单击事件逻辑
            SetStyle(ControlStyles.StandardDoubleClick, false);//停用双加事件

            this.OnSkinChanged();
        }

        #region 重写

        protected override void OnScaleDpiChangedInitialize()
        {
            this.InitializeElement();
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            int scale_contentPadding = (int)Math.Ceiling(this.contentPadding * this.ScaleDpi);
            Rectangle content_rect = new Rectangle(scale_contentPadding, scale_contentPadding, this.ClientRectangle.Width - scale_contentPadding * 2, this.ClientRectangle.Height - scale_contentPadding * 2);
            MultidropSlideTrackMargin scale_oientationMargin = new MultidropSlideTrackMargin((int)Math.Ceiling(this.OrientationMargin.TrackTitle * this.ScaleDpi), (int)Math.Ceiling(this.OrientationMargin.TrackStart * this.ScaleDpi), (int)Math.Ceiling(this.OrientationMargin.TrackEnd * this.ScaleDpi));
            int scale_poleRadius = (int)(Math.Ceiling(this.Track.Thickness * this.ScaleDpi) / 2);
            int scale_poleDiameter = scale_poleRadius * 2;
            int scale_lumpRadius = (int)(Math.Ceiling(this.Thumb.Diameter * this.ScaleDpi) / 2);
            int scale_lumpDiameter = scale_lumpRadius * 2;
            int lock_back_diameter = scale_lumpRadius;
            StyleAppearanceObject.ItemAppearanceObject itemAppearance = this.Enabled ? this.StyleAppearance.Normal : this.StyleAppearance.Disabled;


            //轨道
            Pen pole_back_pen = new Pen(itemAppearance.TrackBackColor, scale_poleDiameter) { Alignment = PenAlignment.Center };
            if (this.Track.RoundEnabled)
            {
                pole_back_pen.StartCap = LineCap.Round;
                pole_back_pen.EndCap = LineCap.Round;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.InterpolationMode = InterpolationMode.High;
            }
            if (this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom)
            {
                if (this.Track.RoundEnabled)
                {
                    g.DrawLine(pole_back_pen, this.pole_start_point.X - scale_lumpRadius + scale_poleRadius, this.pole_start_point.Y, this.pole_end_point.X + scale_lumpRadius - scale_poleRadius, this.pole_start_point.Y);
                }
                else
                {
                    g.DrawLine(pole_back_pen, this.pole_start_point.X - scale_lumpRadius, this.pole_start_point.Y, this.pole_end_point.X + scale_lumpRadius, this.pole_start_point.Y);
                }
            }
            else
            {
                if (this.Track.RoundEnabled)
                {
                    g.DrawLine(pole_back_pen, this.pole_start_point.X, this.pole_start_point.Y + scale_lumpRadius - scale_poleRadius, this.pole_end_point.X, this.pole_end_point.Y - scale_lumpRadius + scale_poleRadius);
                }
                else
                {
                    g.DrawLine(pole_back_pen, this.pole_start_point.X, this.pole_start_point.Y + scale_lumpRadius, this.pole_end_point.X, this.pole_end_point.Y - scale_lumpRadius);
                }
            }
            pole_back_pen.Dispose();

            // 滑块
            SolidBrush lump_back_sb = null;
            Pen lump_border_sb = null;
            SolidBrush lump_lock_sb = null;

            SolidBrush commom_lump_back_sb = null;
            bool commom_lump_back_sb_istmp = false;
            Pen commom_lump_border_sb = null;
            bool commom_lump_border_sb_istmp = false;
            SolidBrush commom_lump_lock_sb = null;
            bool commom_lump_lock_sb_istmp = false;

            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.High;
            for (int i = 0; i < this.Items.Count; i++)
            {
                MultidropSlideThumb.StyleObject.ItemObject itemAppearanceObject = this.Enabled ? this.Items[i].StyleAppearance.Normal : this.Items[i].StyleAppearance.Disabled;
                // 滑块
                if (itemAppearanceObject.ThumbBackColor == Color.Empty)
                {
                    if (lump_back_sb == null)
                    {
                        lump_back_sb = new SolidBrush(itemAppearance.ThumbBackColor);
                    }
                    commom_lump_back_sb = lump_back_sb;
                    commom_lump_back_sb_istmp = false;
                }
                else
                {
                    commom_lump_back_sb = new SolidBrush(itemAppearanceObject.ThumbBackColor);
                    commom_lump_back_sb_istmp = true;

                }
                g.FillEllipse(commom_lump_back_sb, this.Items[i].LumpRect);

                //滑块边框
                if (itemAppearanceObject.ThumbBorderColor == Color.Empty)
                {
                    if (lump_border_sb == null)
                    {
                        lump_border_sb = new Pen(itemAppearance.ThumbBorderColor);
                    }
                    commom_lump_border_sb = lump_border_sb;
                    commom_lump_border_sb_istmp = false;
                }
                else
                {
                    commom_lump_border_sb = new Pen(itemAppearanceObject.ThumbBorderColor);
                    commom_lump_border_sb_istmp = true;

                }
                g.DrawEllipse(commom_lump_border_sb, this.Items[i].LumpRect);

                // 滑块锁
                if (this.Items[i].LumpLocked)
                {
                    RectangleF lump_lock_back_rectf = new RectangleF(this.Items[i].LumpRect.X + (this.Items[i].LumpRect.Width - lock_back_diameter) / 2f, this.Items[i].LumpRect.Y + (this.Items[i].LumpRect.Height - lock_back_diameter) / 2f, lock_back_diameter, lock_back_diameter);

                    if (itemAppearanceObject.ThumbLockColor == Color.Empty)
                    {
                        if (lump_lock_sb == null)
                        {
                            lump_lock_sb = new SolidBrush(itemAppearance.ThumbLockColor);
                        }
                        commom_lump_lock_sb = lump_lock_sb;
                        commom_lump_lock_sb_istmp = false;
                    }
                    else
                    {
                        commom_lump_lock_sb = new SolidBrush(itemAppearanceObject.ThumbLockColor);
                        commom_lump_lock_sb_istmp = true;
                    }
                    g.FillEllipse(commom_lump_lock_sb, lump_lock_back_rectf);
                }

                // 控件激活的虚线框
                if (this.Focused && (this.ShowFocusCues || this.activatedState) && this.activatedIndex == i)
                {
                    RectangleF activate_rectf = new RectangleF(this.Items[this.activatedIndex].LumpRect.X + 3, this.Items[this.activatedIndex].LumpRect.Y + 3, this.Items[this.activatedIndex].LumpRect.Width - 6, this.Items[this.activatedIndex].LumpRect.Height - 6);
                    Pen activate_border_pen = new Pen(this.StyleAppearance.ActivateColor) { DashStyle = DashStyle.Dot };
                    g.DrawEllipse(activate_border_pen, activate_rectf);
                    activate_border_pen.Dispose();
                }

                if (commom_lump_back_sb_istmp && commom_lump_back_sb != null)
                {
                    commom_lump_back_sb.Dispose();
                    commom_lump_back_sb = null;
                }
                if (commom_lump_border_sb_istmp && commom_lump_border_sb != null)
                {
                    commom_lump_border_sb.Dispose();
                    commom_lump_border_sb = null;
                }
                if (commom_lump_lock_sb_istmp && commom_lump_lock_sb != null)
                {
                    commom_lump_lock_sb.Dispose();
                    commom_lump_lock_sb = null;
                }

            }

            if (lump_back_sb != null)
                lump_back_sb.Dispose();
            if (lump_border_sb != null)
                lump_border_sb.Dispose();
            if (lump_lock_sb != null)
                lump_lock_sb.Dispose();

            // 标题提示
            if (this.TipTitle.Visible)
            {
                NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.TipTitle.Font);
                int scale_padding = (int)Math.Ceiling(4 * this.ScaleDpi);
                int scale_tipTitleDistance = (int)(this.TipTitle.LineDistance * this.ScaleDpi);
                int scale_tipTitleInterval = (int)(this.tipTitleInterval * this.ScaleDpi);

                SolidBrush tip_title_back_sb = null;
                SolidBrush tip_title_fore_sb = null;
                Pen tip_title_line_pen = null;

                SolidBrush commom_tip_title_back_sb = null;
                bool commom_tip_title_back_sb_istmp = false;
                SolidBrush commom_tip_title_fore_sb = null;
                bool commom_tip_title_fore_sb_istmp = false;
                Pen commom_tip_title_line_pen = null;
                bool commom_tip_title_line_pen_istmp = false;

                int next_x = 0;
                int next_b = 0;
                //计算标题提示的位置
                for (int i = this.Items.Count - 1; i >= 0; i--)
                {
                    this.Items[i].TipTitleSize = new Size((int)Math.Ceiling(g.MeasureString(this.Items[i].Title, this.TipTitle.Font, int.MaxValue, StringFormat.GenericTypographic).Width), font_metrics.GetFontRealHeight());
                    Rectangle tip_title_back_rect = new Rectangle(0, 0, scale_padding + this.Items[i].TipTitleSize.Width + scale_padding, scale_padding + this.Items[i].TipTitleSize.Height + scale_padding);

                    if (this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom)
                    {
                        tip_title_back_rect.X = (int)(this.Items[i].LumpRect.X + this.Items[i].LumpRect.Width / 2f - tip_title_back_rect.Width / 2f);
                        if (i == this.Items.Count - 1 && tip_title_back_rect.Right > content_rect.Right)
                        {
                            tip_title_back_rect.X = content_rect.Right - tip_title_back_rect.Width;
                        }
                        if (i < this.Items.Count - 1 && tip_title_back_rect.Right > next_x)
                        {
                            tip_title_back_rect.X = next_x - tip_title_back_rect.Width;
                        }
                        next_x = tip_title_back_rect.X - (tip_title_back_rect.Width == 0 ? 0 : scale_tipTitleInterval);

                        if (this.Orientation == MultidropSlideOrientation.HorizontalTop)
                        {
                            tip_title_back_rect.Y = (int)this.Items[i].LumpRect.Y - scale_tipTitleDistance - tip_title_back_rect.Height;
                        }
                        else
                        {
                            tip_title_back_rect.Y = (int)this.Items[i].LumpRect.Bottom + scale_tipTitleDistance;
                        }
                    }
                    else if (this.Orientation == MultidropSlideOrientation.VerticalLeft || this.Orientation == MultidropSlideOrientation.VerticalRight)
                    {
                        tip_title_back_rect.Y = (int)(this.Items[i].LumpRect.Y + this.Items[i].LumpRect.Height / 2f - tip_title_back_rect.Height / 2f);
                        if (i == this.Items.Count - 1 && tip_title_back_rect.Y < content_rect.Y)
                        {
                            tip_title_back_rect.Y = content_rect.Y;
                        }
                        if (i < this.Items.Count - 1 && tip_title_back_rect.Y < next_b)
                        {
                            tip_title_back_rect.Y = next_b;
                        }
                        next_b = tip_title_back_rect.Bottom + (tip_title_back_rect.Height == 0 ? 0 : scale_tipTitleInterval);

                        if (this.Orientation == MultidropSlideOrientation.VerticalLeft)
                        {
                            tip_title_back_rect.X = (int)this.Items[i].LumpRect.X - scale_tipTitleDistance - this.Items[i].TipTitleSize.Width;
                        }
                        else
                        {
                            tip_title_back_rect.X = (int)this.Items[i].LumpRect.Right + scale_tipTitleDistance;
                        }
                    }

                    this.Items[i].TipTitleRect = tip_title_back_rect;
                }
                //验证提示信息的位置与绘制
                g.SmoothingMode = SmoothingMode.Default;
                g.InterpolationMode = InterpolationMode.Default;
                int prev_x = 0;
                int prev_y = 0;
                for (int i = 0; i < this.Items.Count; i++)
                {
                    if (String.IsNullOrEmpty(this.Items[i].Title))
                    {
                        continue;
                    }

                    if (this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom)
                    {
                        if (i == 0)
                        {
                            if (this.Items[i].TipTitleRect.X < content_rect.X)
                                this.Items[i].TipTitleRect = new Rectangle(content_rect.X, this.Items[i].TipTitleRect.Y, this.Items[i].TipTitleRect.Width, this.Items[i].TipTitleRect.Height);
                        }
                        else
                        {
                            if (this.Items[i].TipTitleRect.X < prev_x)
                                this.Items[i].TipTitleRect = new Rectangle(prev_x, this.Items[i].TipTitleRect.Y, this.Items[i].TipTitleRect.Width, this.Items[i].TipTitleRect.Height);
                        }
                        prev_x = this.Items[i].TipTitleRect.Right + (this.Items[i].TipTitleRect.Width == 0 ? 0 : scale_tipTitleInterval);

                        if (this.Orientation == MultidropSlideOrientation.HorizontalTop)
                        {
                            this.Items[i].TipTitleStartPoint = new PointF(this.Items[i].LumpRect.X + this.Items[i].LumpRect.Width / 2, this.Items[i].LumpRect.Y);
                            this.Items[i].TipTitleEndPoint = new PointF(this.Items[i].TipTitleRect.X + this.Items[i].TipTitleRect.Width / 2, this.Items[i].TipTitleRect.Bottom);
                        }
                        else
                        {
                            this.Items[i].TipTitleStartPoint = new PointF(this.Items[i].LumpRect.X + this.Items[i].LumpRect.Width / 2, this.Items[i].LumpRect.Bottom);
                            this.Items[i].TipTitleEndPoint = new PointF(this.Items[i].TipTitleRect.X + this.Items[i].TipTitleRect.Width / 2, this.Items[i].TipTitleRect.Y);
                        }
                    }
                    else if (this.Orientation == MultidropSlideOrientation.VerticalLeft || this.Orientation == MultidropSlideOrientation.VerticalRight)
                    {
                        if (i == 0)
                        {
                            if (this.Items[i].TipTitleRect.Bottom > content_rect.Bottom)
                                this.Items[i].TipTitleRect = new Rectangle(this.Items[i].TipTitleRect.X, (int)(content_rect.Bottom - this.Items[i].TipTitleRect.Height), this.Items[i].TipTitleRect.Width, this.Items[i].TipTitleRect.Height);
                        }
                        else
                        {
                            if (this.Items[i].TipTitleRect.Bottom > prev_y)
                                this.Items[i].TipTitleRect = new Rectangle(this.Items[i].TipTitleRect.X, prev_y - this.Items[i].TipTitleRect.Height, this.Items[i].TipTitleRect.Width, this.Items[i].TipTitleRect.Height);
                        }
                        prev_y = this.Items[i].TipTitleRect.Y - (this.Items[i].TipTitleRect.Height == 0 ? 0 : scale_tipTitleInterval);

                        if (this.Orientation == MultidropSlideOrientation.VerticalLeft)
                        {
                            this.Items[i].TipTitleStartPoint = new PointF(this.Items[i].LumpRect.Left, this.Items[i].LumpRect.Bottom - this.Items[i].LumpRect.Height / 2);
                            this.Items[i].TipTitleEndPoint = new PointF(this.Items[i].TipTitleRect.Right, this.Items[i].TipTitleRect.Bottom - this.Items[i].TipTitleRect.Height / 2);
                        }
                        else
                        {
                            this.Items[i].TipTitleStartPoint = new PointF(this.Items[i].LumpRect.Right, this.Items[i].LumpRect.Bottom - this.Items[i].LumpRect.Height / 2);
                            this.Items[i].TipTitleEndPoint = new PointF(this.Items[i].TipTitleRect.X, this.Items[i].TipTitleRect.Bottom - this.Items[i].TipTitleRect.Height / 2);
                        }
                    }

                    MultidropSlideThumb.StyleObject.ItemObject itemAppearanceObject = this.Enabled ? this.Items[i].StyleAppearance.Normal : this.Items[i].StyleAppearance.Disabled;
                    if (itemAppearanceObject.TipTitleBackColor == Color.Empty)
                    {
                        if (tip_title_back_sb == null)
                        {
                            tip_title_back_sb = new SolidBrush(itemAppearance.TipTitleBackColor);
                        }
                        commom_tip_title_back_sb = tip_title_back_sb;
                        commom_tip_title_back_sb_istmp = false;
                        if (tip_title_line_pen == null)
                        {
                            tip_title_line_pen = new Pen(itemAppearance.TipTitleBorderColor, 2);
                        }
                        commom_tip_title_line_pen = tip_title_line_pen;
                        commom_tip_title_line_pen_istmp = false;
                    }
                    else
                    {
                        commom_tip_title_back_sb = new SolidBrush(itemAppearanceObject.TipTitleBackColor);
                        commom_tip_title_back_sb_istmp = true;
                        commom_tip_title_line_pen = new Pen(itemAppearanceObject.TipTitleBackColor, 2);
                        commom_tip_title_line_pen_istmp = true;
                    }
                    if (itemAppearanceObject.TipTitleTextColor == Color.Empty)
                    {
                        if (tip_title_fore_sb == null)
                        {
                            tip_title_fore_sb = new SolidBrush(itemAppearance.TipTitleTextColor);
                        }
                        commom_tip_title_fore_sb = tip_title_fore_sb;
                        commom_tip_title_fore_sb_istmp = false;
                    }
                    else
                    {
                        commom_tip_title_fore_sb = new SolidBrush(itemAppearanceObject.TipTitleTextColor);
                        commom_tip_title_fore_sb_istmp = true;
                    }

                    commom_tip_title_line_pen.Width = 2;
                    g.DrawLine(commom_tip_title_line_pen, this.Items[i].TipTitleStartPoint, this.Items[i].TipTitleEndPoint);
                    g.FillRectangle(commom_tip_title_back_sb, this.Items[i].TipTitleRect);
                    g.DrawString(this.Items[i].Title, this.TipTitle.Font, commom_tip_title_fore_sb, (this.Items[i].TipTitleRect.X + (this.Items[i].TipTitleRect.Width - this.Items[i].TipTitleSize.Width) / 2), (this.Items[i].TipTitleRect.Y + (this.Items[i].TipTitleRect.Height - this.Items[i].TipTitleSize.Height) / 2), StringFormat.GenericTypographic);
                    commom_tip_title_line_pen.Width = 1;
                    g.DrawRectangle(commom_tip_title_line_pen, new Rectangle(this.Items[i].TipTitleRect.X, this.Items[i].TipTitleRect.Y, this.Items[i].TipTitleRect.Width - 1, this.Items[i].TipTitleRect.Height - 1));

                    if (commom_tip_title_back_sb_istmp && commom_tip_title_back_sb != null)
                    {
                        commom_tip_title_back_sb.Dispose();
                        commom_tip_title_back_sb = null;
                    }
                    if (commom_tip_title_fore_sb_istmp && commom_tip_title_fore_sb != null)
                    {
                        commom_tip_title_fore_sb.Dispose();
                        commom_tip_title_fore_sb = null;
                    }
                    if (commom_tip_title_line_pen_istmp && commom_tip_title_line_pen != null)
                    {
                        commom_tip_title_line_pen.Dispose();
                        commom_tip_title_line_pen = null;
                    }

                }

                if (tip_title_back_sb != null)
                    tip_title_back_sb.Dispose();
                if (tip_title_fore_sb != null)
                    tip_title_fore_sb.Dispose();
                if (tip_title_line_pen != null)
                    tip_title_line_pen.Dispose();
            }

            // 值提示
            if (this.TipValue.Visible)
            {
                NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.TipValue.Font);
                int scale_padding = font_metrics.GetFontStereotypesMargim();
                int scale_tipValueSpace = (int)(this.TipValue.LineDistance * this.ScaleDpi);
                int scale_tipValueInterval = (int)(this.tipValueInterval * this.ScaleDpi);

                SolidBrush tip_value_back_sb = null;
                SolidBrush tip_value_fore_sb = null;
                Pen tip_value_line_pen = null;

                SolidBrush commom_tip_value_back_sb = null;
                bool commom_tip_value_back_sb_istmp = false;
                SolidBrush commom_tip_value_fore_sb = null;
                bool commom_tip_value_fore_sb_istmp = false;
                Pen commom_tip_value_line_pen = null;
                bool commom_tip_value_line_pen_istmp = false;

                string[] valueTextArr = new string[this.Items.Count];
                for (int i = 0; i < this.Items.Count; i++)
                {
                    MultidropSlideValueFormatEventArgs arg = new MultidropSlideValueFormatEventArgs(this.Items[i], this.Items[i].SelfValue.ToString());
                    this.OnValueFormat(arg);
                    valueTextArr[i] = arg.ValueFormat;
                }

                int next_x = 0;
                int next_b = 0;
                //计算值提示的位置
                for (int i = this.Items.Count - 1; i >= 0; i--)
                {
                    this.Items[i].TipValueSize = new Size((int)Math.Ceiling(g.MeasureString(valueTextArr[i], this.TipValue.Font, int.MaxValue, StringFormat.GenericTypographic).Width), font_metrics.GetFontRealHeight());
                    Rectangle tip_value_back_rect = new Rectangle(0, 0, scale_padding + this.Items[i].TipValueSize.Width + scale_padding, scale_padding + this.Items[i].TipValueSize.Height + scale_padding);

                    if (this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom)
                    {
                        tip_value_back_rect.X = (int)(this.Items[i].LumpRect.X + this.Items[i].LumpRect.Width / 2f - tip_value_back_rect.Width / 2f);
                        if (i == this.Items.Count - 1 && tip_value_back_rect.Right > content_rect.Right)
                        {
                            tip_value_back_rect.X = content_rect.Right - tip_value_back_rect.Width;
                        }
                        if (i < this.Items.Count - 1 && tip_value_back_rect.Right > next_x)
                        {
                            tip_value_back_rect.X = next_x - tip_value_back_rect.Width;
                        }
                        next_x = tip_value_back_rect.X - (tip_value_back_rect.Width == 0 ? 0 : scale_tipValueInterval);


                        if (this.Orientation == MultidropSlideOrientation.HorizontalTop)
                        {
                            tip_value_back_rect.Y = (int)this.Items[i].LumpRect.Bottom + scale_tipValueSpace;
                        }
                        else
                        {
                            tip_value_back_rect.Y = (int)this.Items[i].LumpRect.Y - scale_tipValueSpace - tip_value_back_rect.Height;
                        }
                    }
                    else if (this.Orientation == MultidropSlideOrientation.VerticalLeft || this.Orientation == MultidropSlideOrientation.VerticalRight)
                    {
                        tip_value_back_rect.Y = (int)(this.Items[i].LumpRect.Y + this.Items[i].LumpRect.Height / 2f - tip_value_back_rect.Height / 2f);
                        if (i == this.Items.Count - 1 && tip_value_back_rect.Y < content_rect.Y)
                        {
                            tip_value_back_rect.Y = content_rect.Y;
                        }
                        if (i < this.Items.Count - 1 && tip_value_back_rect.Y < next_b)
                        {
                            tip_value_back_rect.Y = next_b;
                        }
                        next_b = tip_value_back_rect.Bottom + (tip_value_back_rect.Height == 0 ? 0 : scale_tipValueInterval);

                        if (this.Orientation == MultidropSlideOrientation.VerticalLeft)
                        {
                            tip_value_back_rect.X = (int)this.Items[i].LumpRect.Right + scale_tipValueSpace;
                        }
                        else
                        {
                            tip_value_back_rect.X = (int)this.Items[i].LumpRect.X - scale_tipValueSpace - this.Items[i].TipValueSize.Width;
                        }
                    }

                    this.Items[i].TipValueRect = tip_value_back_rect;
                }
                //验证提示信息的位置与绘制
                g.SmoothingMode = SmoothingMode.Default;
                g.InterpolationMode = InterpolationMode.Default;
                int prev_x = 0;
                int prev_y = 0;
                for (int i = 0; i < this.Items.Count; i++)
                {
                    if (String.IsNullOrEmpty(valueTextArr[i]))
                    {
                        continue;
                    }

                    if (this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom)
                    {
                        if (i == 0)
                        {
                            if (this.Items[i].TipValueRect.X < content_rect.X)
                                this.Items[i].TipValueRect = new Rectangle(content_rect.X, this.Items[i].TipValueRect.Y, this.Items[i].TipValueRect.Width, this.Items[i].TipValueRect.Height);
                        }
                        else
                        {
                            if (this.Items[i].TipValueRect.X < prev_x)
                                this.Items[i].TipValueRect = new Rectangle(prev_x, this.Items[i].TipValueRect.Y, this.Items[i].TipValueRect.Width, this.Items[i].TipValueRect.Height);
                        }
                        prev_x = this.Items[i].TipValueRect.Right + (this.Items[i].TipValueRect.Width == 0 ? 0 : scale_tipValueInterval);


                        if (this.Orientation == MultidropSlideOrientation.HorizontalTop)
                        {
                            this.Items[i].TipValueStartPoint = new PointF(this.Items[i].LumpRect.X + this.Items[i].LumpRect.Width / 2, this.Items[i].LumpRect.Bottom);
                            this.Items[i].TipValueEndPoint = new PointF(this.Items[i].TipValueRect.X + this.Items[i].TipValueRect.Width / 2, this.Items[i].TipValueRect.Y);
                        }
                        else
                        {
                            this.Items[i].TipValueStartPoint = new PointF(this.Items[i].LumpRect.X + this.Items[i].LumpRect.Width / 2, this.Items[i].LumpRect.Y);
                            this.Items[i].TipValueEndPoint = new PointF(this.Items[i].TipValueRect.X + this.Items[i].TipValueRect.Width / 2, this.Items[i].TipValueRect.Bottom);
                        }
                    }
                    else if (this.Orientation == MultidropSlideOrientation.VerticalLeft || this.Orientation == MultidropSlideOrientation.VerticalRight)
                    {
                        if (i == 0)
                        {
                            if (this.Items[i].TipValueRect.Bottom > content_rect.Bottom)
                                this.Items[i].TipValueRect = new Rectangle(this.Items[i].TipValueRect.X, (int)(content_rect.Bottom - this.Items[i].TipValueRect.Height), this.Items[i].TipValueRect.Width, this.Items[i].TipValueRect.Height);
                        }
                        else
                        {
                            if (this.Items[i].TipValueRect.Bottom > prev_y)
                                this.Items[i].TipValueRect = new Rectangle(this.Items[i].TipValueRect.X, prev_y - this.Items[i].TipValueRect.Height, this.Items[i].TipValueRect.Width, this.Items[i].TipValueRect.Height);
                        }
                        prev_y = this.Items[i].TipValueRect.Y - (this.Items[i].TipValueRect.Height == 0 ? 0 : scale_tipValueInterval);

                        if (this.Orientation == MultidropSlideOrientation.VerticalLeft)
                        {
                            this.Items[i].TipValueStartPoint = new PointF(this.Items[i].LumpRect.Right, this.Items[i].LumpRect.Bottom - this.Items[i].LumpRect.Height / 2);
                            this.Items[i].TipValueEndPoint = new PointF(this.Items[i].TipValueRect.Left, this.Items[i].TipValueRect.Bottom - this.Items[i].TipValueRect.Height / 2);
                        }
                        else
                        {
                            this.Items[i].TipValueStartPoint = new PointF(this.Items[i].LumpRect.X, this.Items[i].LumpRect.Bottom - this.Items[i].LumpRect.Height / 2);
                            this.Items[i].TipValueEndPoint = new PointF(this.Items[i].TipValueRect.Right, this.Items[i].TipValueRect.Bottom - this.Items[i].TipValueRect.Height / 2);
                        }
                    }

                    MultidropSlideThumb.StyleObject.ItemObject itemAppearanceObject = this.Enabled ? this.Items[i].StyleAppearance.Normal : this.Items[i].StyleAppearance.Disabled;

                    if (itemAppearanceObject.TipValueBackColor == Color.Empty)
                    {
                        if (tip_value_back_sb == null)
                        {
                            tip_value_back_sb = new SolidBrush(itemAppearance.TipValueBackColor);
                        }
                        commom_tip_value_back_sb = tip_value_back_sb;
                        commom_tip_value_back_sb_istmp = false;
                        if (tip_value_line_pen == null)
                        {
                            tip_value_line_pen = new Pen(itemAppearance.TipValueBorderColor, 2);
                        }
                        commom_tip_value_line_pen = tip_value_line_pen;
                        commom_tip_value_line_pen_istmp = false;
                    }
                    else
                    {
                        commom_tip_value_back_sb = new SolidBrush(itemAppearanceObject.TipValueBackColor);
                        commom_tip_value_back_sb_istmp = true;
                        commom_tip_value_line_pen = new Pen(itemAppearanceObject.TipValueBackColor, 2);
                        commom_tip_value_line_pen_istmp = true;
                    }
                    if (itemAppearanceObject.TipValueTextColor == Color.Empty)
                    {
                        if (tip_value_fore_sb == null)
                        {
                            tip_value_fore_sb = new SolidBrush(itemAppearance.TipValueTextColor);
                        }
                        commom_tip_value_fore_sb = tip_value_fore_sb;
                        commom_tip_value_fore_sb_istmp = false;
                    }
                    else
                    {
                        commom_tip_value_fore_sb = new SolidBrush(itemAppearanceObject.TipValueTextColor);
                        commom_tip_value_fore_sb_istmp = true;
                    }

                    commom_tip_value_line_pen.Width = 2;
                    g.DrawLine(commom_tip_value_line_pen, this.Items[i].TipValueStartPoint, this.Items[i].TipValueEndPoint);
                    g.FillRectangle(commom_tip_value_back_sb, this.Items[i].TipValueRect);
                    g.DrawString(valueTextArr[i], this.TipValue.Font, commom_tip_value_fore_sb, (this.Items[i].TipValueRect.X + (this.Items[i].TipValueRect.Width - this.Items[i].TipValueSize.Width) / 2), (this.Items[i].TipValueRect.Y + (this.Items[i].TipValueRect.Height - this.Items[i].TipValueSize.Height) / 2), StringFormat.GenericTypographic);
                    commom_tip_value_line_pen.Width = 1;
                    g.DrawRectangle(commom_tip_value_line_pen, new Rectangle(this.Items[i].TipValueRect.X, this.Items[i].TipValueRect.Y, this.Items[i].TipValueRect.Width - 1, this.Items[i].TipValueRect.Height - 1));

                    if (commom_tip_value_back_sb_istmp && commom_tip_value_back_sb != null)
                    {
                        commom_tip_value_back_sb.Dispose();
                        commom_tip_value_back_sb = null;
                    }
                    if (commom_tip_value_fore_sb_istmp && commom_tip_value_fore_sb != null)
                    {
                        commom_tip_value_fore_sb.Dispose();
                        commom_tip_value_fore_sb = null;
                    }
                    if (commom_tip_value_line_pen_istmp && commom_tip_value_line_pen != null)
                    {
                        commom_tip_value_line_pen.Dispose();
                        commom_tip_value_line_pen = null;
                    }

                }

                if (tip_value_back_sb != null)
                    tip_value_back_sb.Dispose();
                if (tip_value_fore_sb != null)
                    tip_value_fore_sb.Dispose();
                if (tip_value_line_pen != null)
                    tip_value_line_pen.Dispose();
            }

        }

        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);

            for (int i = 0; i < this.Items.Count; i++)
            {
                if (!this.Items[i].LumpLocked)
                {
                    this.activatedIndex = i;
                    break;
                }
            }
            this.Invalidate();
        }

        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);

            this.mousedownobjectindex = -1;
            this.mousedownobjectvalue = -1;
            this.mousedownpoint = Point.Empty;
            this.activatedState = false;
            this.Invalidate();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!this.Focused)
            {
                this.Focus();
            }

            int mousedownobjectindex_tmp = -1;
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                for (int i = 0; i < this.Items.Count; i++)
                {
                    if (this.Items[i].LumpRect.Contains(e.Location))
                    {
                        GraphicsPath gp = new GraphicsPath();
                        gp.AddEllipse(this.Items[i].LumpRect);
                        if (gp.IsVisible(e.Location))
                        {
                            if (!this.Items[i].LumpLocked)
                            {
                                mousedownobjectindex_tmp = i;
                                this.activatedIndex = i;
                                this.Invalidate();
                            }
                            gp.Dispose();
                            break;
                        }
                        gp.Dispose();
                    }
                }
            }

            if (mousedownobjectindex_tmp == -1)
            {
                if (this.mousedownobjectindex != mousedownobjectindex_tmp)
                {
                    this.mousedownobjectindex = -1;
                    this.mousedownobjectvalue = -1;
                    this.mousedownpoint = Point.Empty;
                    this.Invalidate();
                }
            }
            else
            {
                if (this.mousedownobjectindex != mousedownobjectindex_tmp)
                {
                    this.mousedownobjectindex = mousedownobjectindex_tmp;
                    this.mousedownobjectvalue = (decimal)this.Items[mousedownobjectindex_tmp].SelfValue;
                    this.mousedownpoint = e.Location;
                    this.Invalidate();
                }
            }

            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            this.mousedownobjectindex = -1;
            this.mousedownobjectvalue = -1;
            this.mousedownpoint = Point.Empty;

            base.OnMouseUp(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!(
                (this.mousedownobjectindex < 0 || this.mousedownobjectindex >= this.Items.Count) ||
                ((this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom) && e.Location.X == this.mousedownpoint.X) ||
                ((this.Orientation == MultidropSlideOrientation.VerticalLeft || this.Orientation == MultidropSlideOrientation.VerticalRight) && e.Location.Y == this.mousedownpoint.Y) ||
                (decimal)this.MaxValue == (decimal)this.MinValue
                ))
            {
                MultidropSlideThumb lump = this.Items[this.mousedownobjectindex];
                bool ishorizontal = (this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom);
                decimal maxminvalue_scope = (decimal)this.MaxValue - (decimal)this.MinValue;
                float allow_track_pixel_scope = (ishorizontal) ? lump.Lump_End_Point - lump.Lump_Start_Point : lump.Lump_Start_Point - lump.Lump_End_Point;
                decimal smallchange_tmp = Math.Min((decimal)this.SmallChange, maxminvalue_scope);

                float mouse_offset = (ishorizontal) ? (e.Location.X - this.mousedownpoint.X) : -(e.Location.Y - this.mousedownpoint.Y);//鼠标移动的偏移量
                decimal value_offset = (decimal)(mouse_offset / allow_track_pixel_scope) * maxminvalue_scope;
                decimal mouse_value = (decimal)lump.SelfValue + value_offset;
                decimal value_tmp = 0;
                if (mouse_value >= (decimal)this.MaxValue && mouse_value != (decimal)lump.SelfValue)
                {
                    value_tmp = (decimal)this.MaxValue;
                }
                else if (mouse_value <= (decimal)this.MinValue && mouse_value != (decimal)lump.SelfValue)
                {
                    value_tmp = (decimal)this.MinValue;
                }
                else if (Math.Abs(value_offset) >= smallchange_tmp)
                {
                    value_tmp = (decimal)lump.SelfValue + smallchange_tmp * (int)(value_offset / smallchange_tmp);
                    value_tmp = Math.Min(value_tmp, (decimal)this.MaxValue);
                    value_tmp = Math.Max(value_tmp, (decimal)this.MinValue);
                }
                else
                {
                    goto result;
                }

                if (value_tmp != (decimal)lump.SelfValue)
                {
                    bool ischange = false;
                    if (e.Button == MouseButtons.Left)
                    {
                        ischange = lump.ChangeSelfValue((double)value_tmp, false);

                    }
                    else if (e.Button == MouseButtons.Right && this.Thumb.InfluencedEnabled)
                    {
                        ischange = lump.ChangeInfluencedValue((double)value_tmp, false);
                    }
                    if (ischange)
                    {
                        decimal smallvalue_representative_pixel = (decimal)allow_track_pixel_scope / (maxminvalue_scope / smallchange_tmp);//单位最小移动间隔代表多少个像素
                        if (ishorizontal)
                        {
                            this.mousedownpoint.X = (int)(lump.Lump_Start_Point + (float)(((decimal)lump.SelfValue - (decimal)this.minValue) / smallchange_tmp * smallvalue_representative_pixel));
                        }
                        else
                        {
                            this.mousedownpoint.Y = (int)(lump.Lump_Start_Point - (float)(((decimal)lump.SelfValue - (decimal)this.minValue) / smallchange_tmp * smallvalue_representative_pixel));
                        }
                    }
                }
            }


        result:
            {

            }
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Left:
                    {
                        this.activatedState = true;

                        int index_tmp = this.activatedIndex - 1;
                        for (int i = index_tmp; i >= -1; i--)
                        {
                            int index = (i > -1) ? i : this.Items.Count - 1;
                            if (!this.Items[index].LumpLocked)
                            {
                                this.activatedIndex = index;
                                this.Invalidate();
                                break;
                            }
                            else if (index == this.Items.Count - 1)
                            {
                                for (int j = index; j > this.activatedIndex; j--)
                                {
                                    if (!this.Items[j].LumpLocked)
                                    {
                                        this.activatedIndex = j;
                                        this.Invalidate();
                                        break;
                                    }
                                }
                            }
                        }

                        return true;
                    }
                case Keys.Right:
                    {
                        this.activatedState = true;

                        int index_tmp = this.activatedIndex + 1;
                        for (int i = index_tmp; i <= this.Items.Count; i++)
                        {
                            int index = (i < this.Items.Count) ? i : 0;
                            if (!this.Items[index].LumpLocked)
                            {
                                this.activatedIndex = index;
                                this.Invalidate();
                                break;
                            }
                            else if (index == 0)
                            {
                                for (int j = index; j < this.activatedIndex; j++)
                                {
                                    if (!this.Items[j].LumpLocked)
                                    {
                                        this.activatedIndex = j;
                                        this.Invalidate();
                                        break;
                                    }
                                }
                            }
                        }

                        return true;
                    }
                case Keys.Control | Keys.Up:
                case Keys.Up:
                    {
                        if (-1 < this.activatedIndex && this.activatedIndex < this.Items.Count)
                        {
                            MultidropSlideThumb lump = this.Items[this.activatedIndex];
                            decimal value_tmp = (decimal)lump.SelfValue + (decimal)this.SmallChange;
                            Math.Min(value_tmp, (decimal)this.MaxValue);
                            if (value_tmp != (decimal)lump.SelfValue)
                            {
                                if (this.Thumb.InfluencedEnabled && keyData.HasFlag(Keys.Control))
                                {
                                    lump.ChangeInfluencedValue((double)value_tmp, false);
                                }
                                else
                                {
                                    if (this.activatedIndex < this.Items.Count - 1)
                                    {
                                        Math.Min(value_tmp, (decimal)this.Items[this.activatedIndex + 1].SelfValue);
                                    }
                                    lump.ChangeSelfValue((double)value_tmp, false);
                                }
                            }
                        }
                        return true;
                    }
                case Keys.Control | Keys.Down:
                case Keys.Down:
                    {
                        if (-1 < this.activatedIndex && this.activatedIndex < this.Items.Count)
                        {
                            MultidropSlideThumb lump = this.Items[this.activatedIndex];
                            decimal value_tmp = (decimal)lump.SelfValue - (decimal)this.SmallChange;
                            Math.Max(value_tmp, (decimal)this.MinValue);
                            if (value_tmp != (decimal)lump.SelfValue)
                            {
                                if (this.Thumb.InfluencedEnabled && keyData.HasFlag(Keys.Control))
                                {
                                    lump.ChangeInfluencedValue((double)value_tmp, false);
                                }
                                else
                                {
                                    if (this.activatedIndex > 0)
                                    {
                                        Math.Max(value_tmp, (decimal)this.Items[this.activatedIndex - 1].SelfValue);
                                    }
                                    lump.ChangeSelfValue((double)value_tmp, false);
                                }
                            }
                        }
                        return true;
                    }

            }

            return base.ProcessDialogKey(keyData);
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            this.InitializeElement();
            this.Invalidate();
        }

        #endregion

        #region 虚方法

        protected internal virtual void OnValueChanged(MultidropSlideValueChangedEventArgs e)
        {
            ValueChangedEventHandler handler = Events[EventValueChanged] as ValueChangedEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnValueFormat(MultidropSlideValueFormatEventArgs e)
        {
            ValueFormatEventHandler handler = Events[EventValueFormat] as ValueFormatEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion

        #region 公开方法

        /// <summary>
        /// 初始化控件内部元素布局
        /// </summary>
        public void InitializeElement()
        {
            int scale_contentPadding = (int)Math.Ceiling(this.contentPadding * this.ScaleDpi);
            Rectangle content_rect = new Rectangle(scale_contentPadding, scale_contentPadding, this.ClientRectangle.Width - scale_contentPadding * 2, this.ClientRectangle.Height - scale_contentPadding * 2);
            MultidropSlideTrackMargin scale_oientationMargin = new MultidropSlideTrackMargin((int)Math.Ceiling(this.OrientationMargin.TrackTitle * this.ScaleDpi), (int)Math.Ceiling(this.OrientationMargin.TrackStart * this.ScaleDpi), (int)Math.Ceiling(this.OrientationMargin.TrackEnd * this.ScaleDpi));
            int scale_poleRadius = (int)(Math.Ceiling(this.Track.Thickness * this.ScaleDpi) / 2);
            int scale_poleDiameter = scale_poleRadius * 2;
            int scale_lumpRadius = (int)(Math.Ceiling(this.Thumb.Diameter * this.ScaleDpi) / 2);
            int scale_lumpDiameter = scale_lumpRadius * 2;
            decimal maxminvalue_scope = (decimal)this.MaxValue - (decimal)this.MinValue;

            //轨道
            if (this.Orientation == MultidropSlideOrientation.HorizontalTop || this.Orientation == MultidropSlideOrientation.HorizontalBottom)
            {
                float pole_back_x_start = content_rect.X + scale_oientationMargin.TrackStart + scale_lumpRadius;
                float pole_back_x_end = Math.Max((content_rect.X + scale_oientationMargin.TrackStart + this.Items.Count * scale_lumpDiameter - scale_lumpRadius), (content_rect.Right - scale_oientationMargin.TrackEnd - scale_lumpRadius));
                float pole_back_y = (this.Orientation == MultidropSlideOrientation.HorizontalTop) ? (content_rect.Y + scale_oientationMargin.TrackTitle + scale_lumpRadius) : (content_rect.Bottom - scale_oientationMargin.TrackTitle - scale_lumpRadius);
                this.pole_start_point = new PointF(pole_back_x_start, pole_back_y);
                this.pole_end_point = new PointF(pole_back_x_end, pole_back_y);
            }
            else
            {
                float pole_back_y_start = content_rect.Bottom - scale_oientationMargin.TrackStart - scale_lumpRadius;
                float pole_back_y_end = content_rect.Y + scale_oientationMargin.TrackEnd + scale_lumpRadius;
                float y_tmp = (content_rect.Bottom - scale_oientationMargin.TrackStart - this.Items.Count * scale_lumpDiameter - scale_lumpRadius);
                if (pole_back_y_end > y_tmp)
                {
                    pole_back_y_end = y_tmp;
                }
                float pole_back_x = (this.Orientation == MultidropSlideOrientation.VerticalLeft) ? (content_rect.X + scale_oientationMargin.TrackTitle + scale_lumpDiameter / 2) : (content_rect.Right - scale_oientationMargin.TrackTitle - scale_lumpDiameter / 2);
                this.pole_start_point = new PointF(pole_back_x, pole_back_y_start);
                this.pole_end_point = new PointF(pole_back_x, pole_back_y_end);
            }

            //滑块
            for (int i = 0; i < this.Items.Count; i++)
            {
                this.InitializeLumpRectangle(this.Items[i], i, maxminvalue_scope, content_rect, scale_oientationMargin, scale_lumpRadius, scale_lumpDiameter);
            }
        }

        #endregion 

        #region 私有方法

        /// <summary>
        /// 初始化指定滑块Rectangle
        /// </summary>
        /// <param name="lump">指定滑块</param>
        /// <param name="lump_index">指定滑块的索引</param>
        /// <param name="maxminvalue_scope">最大最小值的值间距</param>
        /// <param name="content_rect">内容区域</param>
        /// <param name="scale_oientationMargin">MultidropSlide轨道停靠外边距</param>
        /// <param name="scale_lumpRadius">滑块半径</param>
        /// <param name="scale_lumpDiameter">滑块直径</param>
        private void InitializeLumpRectangle(MultidropSlideThumb lump, int lump_index, decimal maxminvalue_scope, Rectangle content_rect, MultidropSlideTrackMargin scale_oientationMargin, int scale_lumpRadius, int scale_lumpDiameter)
        {
            if (this.Orientation == MultidropSlideOrientation.HorizontalBottom || this.Orientation == MultidropSlideOrientation.HorizontalTop)
            {
                lump.Lump_Start_Point = this.pole_start_point.X + lump_index * scale_lumpDiameter;
                lump.Lump_End_Point = this.pole_end_point.X - (this.Items.Count - 1 - lump_index) * scale_lumpDiameter;
                float allow_track_pixel_scope = lump.Lump_End_Point - lump.Lump_Start_Point;
                decimal smallchange_tmp = Math.Min((decimal)this.SmallChange, maxminvalue_scope);
                decimal smallvalue_representative_pixel = (smallchange_tmp == 0) ? 0 : (decimal)allow_track_pixel_scope / (maxminvalue_scope / smallchange_tmp);//单位最小移动间隔代表多少个像素

                float lump_center_x = lump.Lump_Start_Point + (smallchange_tmp == 0 ? 0 : (float)(((decimal)lump.SelfValue - (decimal)this.minValue) / smallchange_tmp * smallvalue_representative_pixel));
                lump_center_x = Math.Max(lump_center_x, lump.Lump_Start_Point);
                lump_center_x = Math.Min(lump_center_x, lump.Lump_End_Point);

                int center_y = (this.Orientation == MultidropSlideOrientation.HorizontalTop) ? (content_rect.Y + scale_oientationMargin.TrackTitle + scale_lumpRadius) : (content_rect.Bottom - scale_oientationMargin.TrackTitle - scale_lumpRadius);
                lump.LumpRect = new RectangleF(lump_center_x - scale_lumpRadius, center_y - scale_lumpRadius, scale_lumpDiameter, scale_lumpDiameter);
            }
            else
            {
                lump.Lump_Start_Point = this.pole_start_point.Y - lump_index * scale_lumpDiameter;
                lump.Lump_End_Point = this.pole_end_point.Y + (this.Items.Count - 1 - lump_index) * scale_lumpDiameter;
                float allow_track_pixel_scope = lump.Lump_Start_Point - lump.Lump_End_Point;
                decimal smallchange_tmp = Math.Min((decimal)this.SmallChange, maxminvalue_scope);
                decimal smallvalue_representative_pixel = (smallchange_tmp == 0) ? 0 : (decimal)allow_track_pixel_scope / (maxminvalue_scope / smallchange_tmp);//单位最小移动间隔代表多少个像素

                float lump_center_y = lump.Lump_Start_Point - (smallchange_tmp == 0 ? 0 : (float)(((decimal)lump.SelfValue - (decimal)this.minValue) / smallchange_tmp * smallvalue_representative_pixel));
                lump_center_y = Math.Min(lump_center_y, lump.Lump_Start_Point);
                lump_center_y = Math.Max(lump_center_y, lump.Lump_End_Point);

                int lump_center_x = (this.Orientation == MultidropSlideOrientation.VerticalLeft) ? (content_rect.X + scale_oientationMargin.TrackTitle + scale_lumpRadius) : (content_rect.Right - scale_oientationMargin.TrackTitle - scale_lumpRadius);
                lump.LumpRect = new RectangleF(lump_center_x - scale_lumpRadius, lump_center_y - scale_lumpRadius, scale_lumpDiameter, scale_lumpDiameter);
            }
        }

        /// <summary>
        /// 初始化指定滑块Rectangle
        /// </summary>
        /// <param name="lump">指定滑块</param>
        internal void InitializeLumpRectangle(MultidropSlideThumb lump)
        {
            int scale_contentPadding = (int)Math.Ceiling(this.contentPadding * this.ScaleDpi);
            Rectangle content_rect = new Rectangle(scale_contentPadding, scale_contentPadding, this.ClientRectangle.Width - scale_contentPadding * 2, this.ClientRectangle.Height - scale_contentPadding * 2);
            MultidropSlideTrackMargin scale_oientationMargin = new MultidropSlideTrackMargin((int)Math.Ceiling(this.OrientationMargin.TrackTitle * this.ScaleDpi), (int)Math.Ceiling(this.OrientationMargin.TrackStart * this.ScaleDpi), (int)Math.Ceiling(this.OrientationMargin.TrackEnd * this.ScaleDpi));
            int scale_poleRadius = (int)(Math.Ceiling(this.Track.Thickness * this.ScaleDpi) / 2);
            int scale_poleDiameter = scale_poleRadius * 2;
            int scale_lumpRadius = (int)(Math.Ceiling(this.Thumb.Diameter * this.ScaleDpi) / 2);
            int scale_lumpDiameter = scale_lumpRadius * 2;
            decimal maxminvalue_scope = (decimal)this.MaxValue - (decimal)this.MinValue;

            int lump_index = this.Items.IndexOf(lump);
            this.InitializeLumpRectangle(lump, lump_index, maxminvalue_scope, content_rect, scale_oientationMargin, scale_lumpRadius, scale_lumpDiameter);
        }

        #endregion

        #region 类

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class TrackObject
        {
            private MultidropSlide owner = null;
            internal TrackObject(MultidropSlide owner) { this.owner = owner; }

            #region 属性

            private bool roundEnabled = true;
            /// <summary>
            /// 轨道是否为圆角
            /// </summary>
            [Description("轨道是否为圆角")]
            [PropertyOrder(-160)]
            [DefaultValue(true)]
            public bool RoundEnabled
            {
                get { return this.roundEnabled; }
                set
                {
                    if (this.roundEnabled == value)
                        return;

                    this.roundEnabled = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private int thickness = 8;
            /// <summary>
            /// 轨道厚度
            /// </summary>
            [Description("轨道厚度")]
            [PropertyOrder(-158)]
            [DefaultValue(8)]
            public int Thickness
            {
                get { return this.thickness; }
                set
                {
                    if (this.thickness == value || value < 0)
                        return;

                    this.thickness = value;
                    if (value > ((MultidropSlide)this.owner).Thumb.Diameter)
                    {
                        ((MultidropSlide)this.owner).Thumb.Diameter = value;
                    }
                    if (this.owner != null)
                    {
                        this.owner.InitializeElement();
                        this.owner.Invalidate();
                    }
                }
            }

            #endregion

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class ThumbObject
        {
            private MultidropSlide owner = null;
            internal ThumbObject(MultidropSlide owner) { this.owner = owner; }

            #region 属性

            private bool influencedEnabled = true;
            /// <summary>
            /// 拇指是否启用受影响功能（可以通过键盘Ctrl+UpDown 或鼠标右键拖动 同时对多个滑块同时更改值）
            /// </summary>
            [Description("拇指是否启用受影响功能（可以通过键盘Ctrl+UpDown 或鼠标右键拖动 同时对多个滑块同时更改值）")]
            [PropertyOrder(-154)]
            [DefaultValue(true)]
            public bool InfluencedEnabled
            {
                get { return this.influencedEnabled; }
                set
                {
                    if (this.influencedEnabled == value)
                        return;

                    this.influencedEnabled = value;
                }
            }

            private int diameter = 18;
            /// <summary>
            /// 拇指直径
            /// </summary>
            [Description("拇指直径")]
            [PropertyOrder(-143)]
            [DefaultValue(18)]
            public int Diameter
            {
                get { return this.diameter; }
                set
                {
                    if (this.diameter == value || value <= 0)
                        return;

                    if (value < ((MultidropSlide)this.owner).Track.Thickness)
                    {
                        value = ((MultidropSlide)this.owner).Track.Thickness;
                    }
                    this.diameter = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeElement();
                        this.owner.Invalidate();
                    }
                }
            }

            #endregion

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class TipTitleObject
        {
            private MultidropSlide owner = null;
            internal TipTitleObject(MultidropSlide owner) { this.owner = owner; }

            #region 属性

            private bool visible = false;
            /// <summary>
            /// 是否显示标题提示
            /// </summary>
            [Description("是否显示标题提示")]
            [PropertyOrder(-130)]
            [DefaultValue(false)]
            public bool Visible
            {
                get { return this.visible; }
                set
                {
                    if (this.visible == value)
                        return;

                    this.visible = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeElement();
                        this.owner.Invalidate();
                    }
                }
            }

            private int lineDistance = 8;
            /// <summary>
            /// 标题提示与滑块间距
            /// </summary>
            [Description("标题提示与滑块间距")]
            [PropertyOrder(-129)]
            [DefaultValue(8)]
            public int LineDistance
            {
                get { return this.lineDistance; }
                set
                {
                    if (this.lineDistance == value || value < 0)
                        return;

                    this.lineDistance = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeElement();
                        this.owner.Invalidate();
                    }
                }
            }

            private Font font = null;
            /// <summary>
            /// 标题提示文本字体
            /// </summary>
            [Description("标题提示文本字体")]
            [PropertyOrder(-128)]
            public Font Font
            {
                get
                {
                    if (this.font != null)
                    {
                        return this.font;
                    }
                    if (((MultidropSlide)this.owner).Parent != null)
                    {
                        return ((MultidropSlide)this.owner).Parent.Font;
                    }
                    return Control.DefaultFont;
                }
                set
                {
                    if (((MultidropSlide)this.owner).Parent != null)
                    {
                        if (((MultidropSlide)this.owner).Parent.Font.Equals(value))
                        {
                            this.font = null;
                            if (this.owner != null)
                            {
                                this.owner.Invalidate();
                            }
                            return;
                        }
                    }
                    if (Control.DefaultFont.Equals(value))
                    {
                        this.font = null;
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                        return;
                    }

                    this.font = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }
            private bool ShouldSerializeFont()
            {
                return (this.font != null && !this.font.Equals(Control.DefaultFont));
            }
            private void ResetFont()
            {
                this.font = null;
                if (this.owner != null)
                {
                    this.owner.Invalidate();
                }
            }

            #endregion

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class TipValueObject
        {
            private MultidropSlide owner = null;
            internal TipValueObject(MultidropSlide owner) { this.owner = owner; }

            #region 属性

            private bool visible = true;
            /// <summary>
            /// 是否显示值提示
            /// </summary>
            [Description("是否显示值提示")]
            [PropertyOrder(-130)]
            [DefaultValue(true)]
            public bool Visible
            {
                get { return this.visible; }
                set
                {
                    if (this.visible == value)
                        return;

                    this.visible = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private int lineDistance = 8;
            /// <summary>
            /// 值提示与滑块间距
            /// </summary>
            [Description("值提示与滑块间距")]
            [PropertyOrder(-129)]
            [DefaultValue(8)]
            public int LineDistance
            {
                get { return this.lineDistance; }
                set
                {
                    if (this.lineDistance == value || value < 0)
                        return;

                    this.lineDistance = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private Font font = null;
            /// <summary>
            /// 值提示文本字体
            /// </summary>
            [Description("值提示文本字体")]
            [PropertyOrder(-128)]
            public Font Font
            {
                get
                {
                    if (this.font != null)
                    {
                        return this.font;
                    }
                    if (((MultidropSlide)this.owner).Parent != null)
                    {
                        return ((MultidropSlide)this.owner).Parent.Font;
                    }
                    return Control.DefaultFont;
                }
                set
                {
                    if (((MultidropSlide)this.owner).Parent != null)
                    {
                        if (((MultidropSlide)this.owner).Parent.Font.Equals(value))
                        {
                            this.font = null;
                            if (this.owner != null)
                            {
                                this.owner.Invalidate();
                            }
                            return;
                        }
                    }
                    if (Control.DefaultFont.Equals(value))
                    {
                        this.font = null;
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                        return;
                    }

                    this.font = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }
            private bool ShouldSerializeFont()
            {
                return (this.font != null && !this.font.Equals(Control.DefaultFont));
            }
            private void ResetFont()
            {
                this.font = null;
                if (this.owner != null)
                {
                    this.owner.Invalidate();
                }
            }

            #endregion

        }

        #endregion

        #region 外观

        public class StyleAppearanceObject : AppearanceObjectBase
        {
            internal StyleAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

            #region 属性

            private Color skinActivateColor = Color.Empty;
            private readonly Color defaultActivateColor = SystemColors.Window;
            private Color activateColor = Color.Empty;
            /// <summary>
            /// 控件激活的虚线框颜色
            /// </summary>
            [Description("控件激活的虚线框颜色")]
            [PropertyOrder(-200)]
            [SkinProperty(true, false)]
            public Color ActivateColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore())
                    {
                        return this.skinActivateColor;
                    }

                    if (this.activateColor != Color.Empty)
                    {
                        return this.activateColor;
                    }

                    return this.defaultActivateColor;
                }
                set
                {
                    if (this.activateColor == value)
                        return;

                    this.activateColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeActivateColor()
            {
                return this.activateColor != Color.Empty;
            }
            private void ResetActivateColor()
            {
                this.activateColor = Color.Empty;
                this.Invalidate();
            }

            private Color skinBackColor = Color.Empty;
            private readonly Color defaultBackColor = SystemColors.Control;
            private Color backColor = Color.Empty;
            /// <summary>
            /// 背景颜色
            /// </summary>
            [Description("背景颜色")]
            [PropertyOrder(-195)]
            [SkinProperty(true, true)]
            public Color BackColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinBackColor != Color.Empty)
                    {
                        return this.skinBackColor;
                    }

                    if (this.backColor != Color.Empty)
                    {
                        return this.backColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.BackColor;
                    }

                    return this.defaultBackColor;
                }
                set
                {
                    if (this.backColor == value)
                        return;

                    this.backColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeBackColor()
            {
                return this.backColor != Color.Empty;
            }
            private void ResetBackColor()
            {
                this.backColor = Color.Empty;
                this.Invalidate();
            }

            private ItemAppearanceObject normal;
            /// <summary>
            /// 正常状态
            /// </summary>
            [Description("正常状态")]
            [PropertyOrder(-194)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public ItemAppearanceObject Normal
            {
                get
                {
                    if (this.normal == null)
                        this.normal = new ItemAppearanceObject(this.owner, this
                            , SystemColors.GradientInactiveCaption
                            , SystemColors.ActiveCaption
                            , SystemColors.GradientActiveCaption
                            , SystemColors.ActiveCaption
                            , SystemColors.ActiveCaption
                            , SystemColors.GradientActiveCaption
                            , SystemColors.Window
                            , SystemColors.ActiveCaption
                            , SystemColors.GradientActiveCaption
                            , SystemColors.Window
                            );
                    return this.normal;
                }
            }

            private ItemAppearanceObject disabled;
            /// <summary>
            /// 禁用状态
            /// </summary>
            [Description("禁用状态")]
            [PropertyOrder(-190)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public ItemAppearanceObject Disabled
            {
                get
                {
                    if (this.disabled == null)
                        this.disabled = new ItemAppearanceObject(this.owner, this
                            , SystemColors.InactiveCaption
                            , SystemColors.InactiveCaption
                            , SystemColors.InactiveCaption
                            , SystemColors.InactiveCaption
                            , SystemColors.InactiveBorder
                            , SystemColors.InactiveCaption
                            , SystemColors.Window
                            , SystemColors.InactiveCaption
                            , SystemColors.InactiveCaption
                            , SystemColors.Window
                            );
                    return this.disabled;
                }
            }

            #endregion

            public class ItemAppearanceObject : AppearanceObjectBase
            {
                internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color trackBackColor, Color thumbBorderColor, Color thumbBackColor, Color thumbLockColor, Color tipTitleBorderColor, Color tipTitleBackColor, Color tipTitleTextColor, Color tipValueBorderColor, Color tipValueBackColor, Color tipValueTextColor) : base(owner, parent)
                {
                    this.defaultTrackBackColor = trackBackColor;
                    this.defaultThumbBorderColor = thumbBorderColor;
                    this.defaultThumbBackColor = thumbBackColor;
                    this.defaultThumbLockColor = thumbLockColor;
                    this.defaultTipTitleBorderColor = tipTitleBorderColor;
                    this.defaultTipTitleBackColor = tipTitleBackColor;
                    this.defaultTipTitleTextColor = tipTitleTextColor;
                    this.defaultTipValueBorderColor = tipValueBorderColor;
                    this.defaultTipValueBackColor = tipValueBackColor;
                    this.defaultTipValueTextColor = tipValueTextColor;
                }

                #region 属性

                private Color skinTrackBackColor = Color.Empty;
                private Color defaultTrackBackColor = Color.Empty;
                private Color trackBackColor = Color.Empty;
                /// <summary>
                /// 轨道背景颜色
                /// </summary>
                [Description("轨道背景颜色")]
                [PropertyOrder(-168)]
                [SkinProperty(true, false)]
                public Color TrackBackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTrackBackColor;
                        }

                        if (this.trackBackColor != Color.Empty)
                        {
                            return this.trackBackColor;
                        }

                        return this.defaultTrackBackColor;
                    }
                    set
                    {
                        if (this.trackBackColor == value)
                            return;

                        this.trackBackColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTrackBackColor()
                {
                    return this.trackBackColor != this.defaultTrackBackColor;
                }
                private void ResetTrackBackColor()
                {
                    this.trackBackColor = this.defaultTrackBackColor;
                    this.Invalidate();
                }

                private Color skinThumbBorderColor = Color.Empty;
                private Color defaultThumbBorderColor = Color.Empty;
                private Color thumbBorderColor = Color.Empty;
                /// <summary>
                /// 拇指边框颜色
                /// </summary>
                [Description("拇指边框颜色")]
                [PropertyOrder(-166)]
                [SkinProperty(true, false)]
                public Color ThumbBorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinThumbBorderColor;
                        }

                        if (this.thumbBorderColor != Color.Empty)
                        {
                            return this.thumbBorderColor;
                        }

                        return this.defaultThumbBorderColor;
                    }
                    set
                    {
                        if (this.thumbBorderColor == value)
                            return;

                        this.thumbBorderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeThumbBorderColor()
                {
                    return this.thumbBorderColor != Color.Empty;
                }
                private void ResetThumbBorderColor()
                {
                    this.thumbBorderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinThumbBackColor = Color.Empty;
                private Color defaultThumbBackColor = Color.Empty;
                private Color thumbBackColor = Color.Empty;
                /// <summary>
                /// 拇指背景颜色
                /// </summary>
                [Description("拇指背景颜色")]
                [PropertyOrder(-164)]
                [SkinProperty(true, false)]
                public Color ThumbBackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinThumbBackColor;
                        }

                        if (this.thumbBackColor != Color.Empty)
                        {
                            return this.thumbBackColor;
                        }

                        return this.defaultThumbBackColor;
                    }
                    set
                    {
                        if (this.thumbBackColor == value)
                            return;

                        this.thumbBackColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeThumbBackColor()
                {
                    return this.thumbBackColor != Color.Empty;
                }
                private void ResetThumbBackColor()
                {
                    this.thumbBackColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinThumbLockColor = Color.Empty;
                private Color defaultThumbLockColor = Color.Empty;
                private Color thumbLockColor = Color.Empty;
                /// <summary>
                /// 拇指锁定颜色
                /// </summary>
                [Description("拇指锁定颜色")]
                [PropertyOrder(-162)]
                [SkinProperty(true, false)]
                public Color ThumbLockColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinThumbLockColor;
                        }

                        if (this.thumbLockColor != Color.Empty)
                        {
                            return this.thumbLockColor;
                        }

                        return this.defaultThumbLockColor;
                    }
                    set
                    {
                        if (this.thumbLockColor == value)
                            return;

                        this.thumbLockColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeThumbLockColor()
                {
                    return this.thumbLockColor != Color.Empty;
                }
                private void ResetThumbLockColor()
                {
                    this.thumbLockColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTipTitleBorderColor = Color.Empty;
                private Color defaultTipTitleBorderColor = Color.Empty;
                private Color tipTitleBorderColor = Color.Empty;
                /// <summary>
                /// 标题提示边框颜色
                /// </summary>
                [Description("标题提示边框颜色")]
                [PropertyOrder(-160)]
                [SkinProperty(true, false)]
                public Color TipTitleBorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTipTitleBorderColor;
                        }

                        if (this.tipTitleBorderColor != Color.Empty)
                        {
                            return this.tipTitleBorderColor;
                        }

                        return this.defaultTipTitleBorderColor;
                    }
                    set
                    {
                        if (this.tipTitleBorderColor == value)
                            return;

                        this.tipTitleBorderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTipTitleBorderColor()
                {
                    return this.tipTitleBorderColor != Color.Empty;
                }
                private void ResetTipTitleBorderColor()
                {
                    this.tipTitleBorderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTipTitleBackColor = Color.Empty;
                private Color defaultTipTitleBackColor = Color.Empty;
                private Color tipTitleBackColor = Color.Empty;
                /// <summary>
                /// 标题提示背景颜色
                /// </summary>
                [Description("标题提示背景颜色")]
                [PropertyOrder(-158)]
                [SkinProperty(true, false)]
                public Color TipTitleBackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTipTitleBackColor;
                        }

                        if (this.tipTitleBackColor != Color.Empty)
                        {
                            return this.tipTitleBackColor;
                        }

                        return this.defaultTipTitleBackColor;
                    }
                    set
                    {
                        if (this.tipTitleBackColor == value)
                            return;

                        this.tipTitleBackColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTipTitleBackColor()
                {
                    return this.tipTitleBackColor != Color.Empty;
                }
                private void ResetTipTitleBackColor()
                {
                    this.tipTitleBackColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTipTitleTextColor = Color.Empty;
                private Color defaultTipTitleTextColor = Color.Empty;
                private Color tipTitleTextColor = Color.Empty;
                /// <summary>
                /// 标题提示文本颜色
                /// </summary>
                [Description("标题提示文本颜色")]
                [PropertyOrder(-156)]
                [SkinProperty(true, false)]
                public Color TipTitleTextColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTipTitleTextColor;
                        }

                        if (this.tipTitleTextColor != Color.Empty)
                        {
                            return this.tipTitleTextColor;
                        }

                        return this.defaultTipTitleTextColor;
                    }
                    set
                    {
                        if (this.tipTitleTextColor == value)
                            return;

                        this.tipTitleTextColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTipTitleTextColor()
                {
                    return this.tipTitleTextColor != Color.Empty;
                }
                private void ResetTipTitleTextColor()
                {
                    this.tipTitleTextColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTipValueBorderColor = Color.Empty;
                private Color defaultTipValueBorderColor = Color.Empty;
                private Color tipValueBorderColor = Color.Empty;
                /// <summary>
                /// 值提示边框颜色
                /// </summary>
                [Description("值提示边框颜色")]
                [PropertyOrder(-154)]
                [SkinProperty(true, false)]
                public Color TipValueBorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTipValueBorderColor;
                        }

                        if (this.tipValueBorderColor != Color.Empty)
                        {
                            return this.tipValueBorderColor;
                        }

                        return this.defaultTipValueBorderColor;
                    }
                    set
                    {
                        if (this.tipValueBorderColor == value)
                            return;

                        this.tipValueBorderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTipValueBorderColor()
                {
                    return this.tipValueBorderColor != Color.Empty;
                }
                private void ResetTipValueBorderColor()
                {
                    this.tipValueBorderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTipValueBackColor = Color.Empty;
                private Color defaultTipValueBackColor = Color.Empty;
                private Color tipValueBackColor = Color.Empty;
                /// <summary>
                /// 值提示背景颜色
                /// </summary>
                [Description("值提示背景颜色")]
                [PropertyOrder(-152)]
                [SkinProperty(true, false)]
                public Color TipValueBackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTipValueBackColor;
                        }

                        if (this.tipValueBackColor != Color.Empty)
                        {
                            return this.tipValueBackColor;
                        }

                        return this.defaultTipValueBackColor;
                    }
                    set
                    {
                        if (this.tipValueBackColor == value)
                            return;

                        this.tipValueBackColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTipValueBackColor()
                {
                    return this.tipValueBackColor != Color.Empty;
                }
                private void ResetTipValueBackColor()
                {
                    this.tipValueBackColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTipValueTextColor = Color.Empty;
                private Color defaultTipValueTextColor = Color.Empty;
                private Color tipValueTextColor = Color.Empty;
                /// <summary>
                /// 值提示文本颜色
                /// </summary>
                [Description("值提示文本颜色")]
                [PropertyOrder(-150)]
                [SkinProperty(true, false)]
                public Color TipValueTextColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTipValueTextColor;
                        }

                        if (this.tipValueTextColor != Color.Empty)
                        {
                            return this.tipValueTextColor;
                        }

                        return this.defaultTipValueTextColor;
                    }
                    set
                    {
                        if (this.tipValueTextColor == value)
                            return;

                        this.tipValueTextColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTipValueTextColor()
                {
                    return this.tipValueTextColor != Color.Empty;
                }
                private void ResetTipValueTextColor()
                {
                    this.tipValueTextColor = Color.Empty;
                    this.Invalidate();
                }

                #endregion

            }

        }

        #endregion

    }
}
